package com.develope.tree;

import java.util.ArrayList;

import org.w3c.dom.ls.LSInput;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ListView;
import android.widget.Toast;

import com.develope.tree.db.DBHelper;

public class ManagerTree extends Activity implements OnItemClickListener{
	
	public final static String EXTRA_MESSAGE1 = "com.develope.tree.MESSAGE1";
	private ListView listView;	
	DBHelper mydb;
	MyArrayAdapter arrayAdapter = null; 	
	ArrayList<Tree> array_list= new ArrayList<Tree>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_manager_tree);
					
		mydb = new DBHelper(this);
		mydb.getReadableDatabase();
		
		array_list = mydb.getAllTree();
				
		arrayAdapter = new MyArrayAdapter(this, R.layout.my_item_layout, array_list);
		listView = (ListView) findViewById(R.id.lvTree);
		listView.setAdapter(arrayAdapter);
		listView.setOnItemClickListener(this);
		listView.setEnabled(true);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		Toast.makeText(this, "item " + arg2, 0).show();
//		int id_To_Search = arg2;
//		Bundle dataBundle = new Bundle();
//		dataBundle.putInt("id", id_To_Search);
//		Intent intent = new Intent(getApplicationContext(), com.develope.tree.displayTree.class);
//		intent.putExtras(dataBundle);
//		startActivity(intent);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.manager_tree, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		super.onOptionsItemSelected(item);
		switch(item.getItemId()){
		case R.id.add_new:
			Bundle dataBundle = new Bundle();
			dataBundle.putString(EXTRA_MESSAGE1, " ");
			Intent intent = new Intent(getApplicationContext(), com.develope.tree.MainActivity.class);
			intent.putExtras(dataBundle);
			startActivity(intent);
			return true;
			
		case R.id.edit_data:
			
			return true;
			
		case R.id.delete_data:
			
			return true;
			
			
	
			
		
		default:
		return super.onOptionsItemSelected(item);
		}
	}
	
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	private void setupActionBar() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
			getActionBar().setDisplayHomeAsUpEnabled(true);
		}
	}


	

}
